import 'package:flutter/material.dart';
import 'package:ninetyfour/l10n/app_localizations.dart';
import '../../models/order_detail_model.dart';
import 'package:flutter/services.dart';

class DetailOrderInfoView extends StatelessWidget {
  final DetailInfoModel model;

  const DetailOrderInfoView({super.key, required this.model});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 0, left: 15, right: 15,bottom: 15),
      padding: const EdgeInsets.all(15), // 内边距，用于增加内部空间，例如文本和图标之间的间距,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
        Padding(
          padding: const EdgeInsets.only(top: 0, bottom: 15),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                AppLocalizations.of(context)!.orderInfo,
                style: const TextStyle(fontSize: 15, color: Color(0xFF333333)),
              ),
              GestureDetector(
                onTap: () async{
                  await Clipboard.setData(ClipboardData(text: model.orderId));
                  ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(content: Text(AppLocalizations.of(context)!.orderIdAlreadyCopy)),
                  );
                },
                child: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
                  decoration: BoxDecoration(
                    color: Color(0xFF5D5FEE), // 浅蓝背景
                    borderRadius: BorderRadius.circular(17),
                  ),
                  child: Text(
                    '${AppLocalizations.of(context)!.copy}${AppLocalizations.of(context)!.order}',
                    style: TextStyle(
                      color: Color(0xFFFFFFFF),
                      fontSize: 13,
                    ),
                  ),
                ),
              )
            ],
          ),
        ),
        const Divider(height: 1, color: Color(0xFFF5F5F5)),
        _buildInfoRow(AppLocalizations.of(context)!.orderNumber, model.orderId),
        _buildInfoRow(AppLocalizations.of(context)!.orderTime, model.createTime),
        if (model.status == 0) ...[
          // 当status为0时显示的组件
        ],
        if (model.status == 4 || model.status == 5)
          _buildInfoRow(AppLocalizations.of(context)!.closeTime, model.cancelTime),
        if (model.status != 4 && model.status != 5 && model.status != 0)
          Column(
            children: [
              _buildInfoRow(AppLocalizations.of(context)!.paymentTime, model.payTime),
              _buildInfoRow(AppLocalizations.of(context)!.paymentmethod, model.payName),
            ],
          ),
      ],

      ),
    );
  }

  Widget _buildInfoRow(String title, String value) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 10),
      child: Row(
        children: [
          SizedBox(
            width: 90, // 固定宽度90
            child: Text(
              title,
              style: const TextStyle(fontSize: 14, color: Color(0xFF666666)),
            ),
          ),
          Expanded(
            child: Text(
              value,
              style: const TextStyle(fontSize: 14, color: Color(0xFF666666)),
              textAlign: TextAlign.right,
            ),
          ),
        ],
      ),
    );
  }
}